package j03gouzao;

public class J1Gouzao {
}

class Dog{
    String name;
    int age;
}
class DogTest{
    public static void main(String[] args) {
        Dog d1 = new Dog();
        d1.name="拉布拉多";
        d1.age=2;

        Dog d2 = new Dog();
        d1.name="泰迪";
        d1.age = 3;
    }
}

//构造方法，解决属性赋值麻烦的问题
class Cat{
    String name;
    int age;

    //构造方法
    /*
    没有返回值，也不要写
    在new的时候，自动调用

    构造方法也可以重载
     */
    //无参构造，意义不大
    public Cat(){
        System.out.println("==cat构造==");
    }
    //有参构造，全参构造
    public Cat(String name,int age){
        System.out.println("==有参构造==");
        this.name = name;
        this.age = age;
    }

    //自定义构造，根据需要确定
    public Cat(String name,int blood,int power){
        System.out.println("==有参构造==");
        this.name = name;
    }
}
class CatTest{
    public static void main(String[] args) {
        Cat c1 = new Cat();
        c1.name = "田园犬";
        c1.age = 5;
        Cat c2 = new Cat("藏獒",9);

        System.out.println("c1.name = " + c1.name);
        System.out.println("c2.name = " + c2.name);
    }
}

class Bird{
    String name;

    //缺点，不方便赋值，
    //有点，创建对象简单，不需要传属性参数
    public Bird(){}

    public Bird(String name){
        this.name = name;
    }
}
class BirdTest{
    public static void main(String[] args) {
        Bird b1 = new Bird();
    }
}